# Create your views here.
from django.shortcuts import render_to_response
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from django.contrib.admin.views.decorators import staff_member_required
from django.template import RequestContext
from models import *

@staff_member_required
def datos_contacto(request, id):
	contacto = Contacto.objects.get(id =id)
	return render_to_response ('datos_contacto.html',locals(), context_instance=RequestContext(request))
		

import datetime

@staff_member_required
def grabar_campo_contacto(request, id):
	contacto = Contacto.objects.get(id =id)
	if request.POST:
		if 'date' in request.POST:
			if request.POST['valor']:
				value = datetime.datetime.strptime(request.POST['valor'], '%d/%m/%Y')
			else:
				value = None
		else:
			value = request.POST['valor']
		setattr(contacto, request.POST['campo'], value)
		contacto.save()
	return HttpResponse("")
		
